using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class EndTurnUI : MonoBehaviour
{
    //[Header("文本设置")]
    //public TMP_Text buttonText;
    //public string playerTurnText = "结束回合";
    //public string enemyTurnText = "敌人回合";

    public BattleManager battleManager;
    
    private bool isPlayerTurn = true;

    void Start()
    {
        if (battleManager == null)
        {
            battleManager = FindObjectOfType<BattleManager>();
        }
        //UpdateButtonAppearance();
    }

    void Update()
    {
        //// 更新回合状态
        //if (battleManager != null)
        //{
        //    bool newTurnState = battleManager.IsPlayerTurn();
            
        //    if (newTurnState != isPlayerTurn)
        //    {
        //        isPlayerTurn = newTurnState;
        //        UpdateButtonAppearance();
        //    }
        //}
    }

    /// <summary>
    /// 鼠标进入
    /// </summary>
    private void OnMouseEnter()
    {
       
    }

    /// <summary>
    /// 鼠标离开
    /// </summary>
    private void OnMouseExit()
    {
        //UpdateButtonAppearance();
    }

    /// <summary>
    /// 鼠标点击
    /// </summary>
    private void OnMouseDown()
    {
        if (isPlayerTurn && battleManager != null)
        {
            Debug.Log("=== EndTurn：结束回合 ===");
            battleManager.EndPlayerTurn();

            // 添加点击反馈
            StartCoroutine(ClickAnimation());
        }
    }

    /// <summary>
    /// 更新按钮外观
    /// </summary>
    //private void UpdateButtonAppearance()
    //{
    //    if (buttonRenderer != null)
    //    {
    //        if (isPlayerTurn)
    //        {
    //            buttonRenderer.material = normalMaterial;
    //        }
    //        else
    //        {
    //            buttonRenderer.material = disabledMaterial;
    //        }
    //    }

    //    if (buttonText != null)
    //    {
    //        buttonText.text = isPlayerTurn ? playerTurnText : enemyTurnText;
    //        buttonText.color = isPlayerTurn ? Color.green : Color.gray;
    //    }
    //}

    /// <summary>
    /// 点击动画
    /// </summary>
    private System.Collections.IEnumerator ClickAnimation()
    {
        Vector3 originalScale = transform.localScale;
        transform.localScale = originalScale * 0.9f;

        yield return new WaitForSeconds(0.1f);

        transform.localScale = originalScale;
    }
}
